﻿
var bookingId;

$(document).ready(function () {

    if ($("#HiddenField1").val() == "ableToSee") {
        $("#contorl").css("display","none");
    }
    else if ($("#HiddenField1").val() == "isApprove") {
        $("#see").css("display", "none");
    }
    $("#weekdays_div").addClass("hidden");
    $("input[name='cycle']").addClass("hidden");
    var obj = document.getElementById("Div1");//得到DIV对象
    var e = obj.getElementsByTagName("INPUT");//得到此DIV里的所有INPUT对象
    for (var i = 0; i < e.length; i++) {
        e[i].disabled = true;
    }
    $("#meetingAbstract").disabled = true;
    $("#cancel").attr("disabled", false);
    $("#goback").attr("disabled", false);
    var id = $("#hdf").val();
    bookingId = $("#hdf").val();
    var options = {
        type: "POST",
        url: "../Booking_confirm.asmx/ShowEveInfor",
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        data: '{"bookingId":"' + id + '"}',
        success: function (response) {
            if (response != null) {
                setEveInfor(response.d);
            }
            if (response == null) {
                alert("没有此条预定信息");
            }
        },
        error: function (result, status) { //如果没有上面的捕获出错会执行这里的回调函数
            alert(status);
        }
    };
    $.ajax(options);

    $("#goback").click(function () {
        location.href = "BookingManage.aspx";
    });

    $("#confirm").click(function () {
        var reson = $("#reason").val();
        var pwd = "";//$("#password").val();
        var options = {
            type: "POST",
            url: "../Booking_confirm.asmx/CancelBooking",
            dataType: "json",
            contentType: "application/json; charset=utf-8",

            data: '{"bookingId":"' + id +
                    '","reason":"' + reson +
                    '","passWord":"' + pwd +
                    '"}',
            success: function (response) {
                if (response != null) {
                    location.href = "../WEB/BookingManage.aspx";
                    alert(response.d)
                }
            },
            error: function (result, status) { //如果没有上面的捕获出错会执行这里的回调函数
                alert(status);
            }
        };
        $.ajax(options)
    })
});


function letDivCenter(divName) {
    var top = ($(window).height() - $(divName).height()) / 2;
    var left = ($(window).width() - $(divName).width()) / 2;
    var scrollTop = $(document).scrollTop();
    var scrollLeft = $(document).scrollLeft();
    $(divName).css({ position: 'absolute', 'top': top + scrollTop, left: left + scrollLeft }).show();
}


function setEveInfor(eveInfor) {
    letDivCenter('#Div1');
    if (eveInfor == null) {
        alert("当前数据为空");
        return;
    }

    $("#participants").html(eveInfor.participants);
    $("#bookingPerson").html(eveInfor.bookingPerson + " &nbsp+" + eveInfor.TelePhoneNumber + " &nbsp" + eveInfor.orgType1 + " &nbsp" + eveInfor.orgType3);
    $("#meetingTheme").html(eveInfor.meetingTheme);
    $("#meetingAbstract").html(eveInfor.meetingAbstract);
    $("#mtrAdd").html(eveInfor.mtrAddress + eveInfor.mtrAddress1 + "  " + eveInfor.mtrName);

    $("#specialRequestFirst").html(eveInfor.specialRequestFirst);
    $("#specialRequestSecond").html(eveInfor.specialRequestSecond);
    var bssd = (new Date(parseFloat((eveInfor.meetingStartDate).substr(6, 13)))).Format("yyyy-MM-dd");
    $("#startDate").html(bssd);
    $("#startTime").html(eveInfor.startTime);
    var bsed = (new Date(parseFloat((eveInfor.meetingEndDate).substr(6, 13)))).Format("yyyy-MM-dd");
    $("#endDate").html(bsed);
    $("#endTime").html(eveInfor.endTime);
    var ss = "容量：" + eveInfor.mtrCapacity + "<br/> 资源： ";
    for (var i = 0 ; i < eveInfor.mtrResName.length; i++) {
        ss = ss + eveInfor.mtrResName[i] + " ";
    }
    $("#moreInfo").html(ss);
    //是否是周期性
    if (eveInfor.isPeriodic) {
        $("input[name='cycle']").get(1).checked = true;
        $("#weekdays_div").removeClass("hidden");
        if (eveInfor.Monday) $("#Monday").attr("checked", "checked");
        if (eveInfor.Tuesday) $("#Tuesday").attr("checked", "checked");
        if (eveInfor.Wednesday) $("#Wednesday").attr("checked", "checked");
        if (eveInfor.Thursday) $("#Thursday").attr("checked", "checked");
        if (eveInfor.Friday) $("#Friday").attr("checked", "checked");
        if (eveInfor.Saturday) $("#Saturday").attr("checked", "checked");
        if (eveInfor.Sunday) $("#Sunday").attr("checked", "checked");
    }
    else if (!eveInfor.isPeriodic) {
        $("#weekdays_div").addClass("hidden");
    }
}

Date.prototype.Format = function (formatStr) {
    var str = formatStr;
    var Week = ['日', '一', '二', '三', '四', '五', '六'];
    str = str.replace(/yyyy|YYYY/, this.getFullYear());
    str = str.replace(/yy|YY/, (this.getYear() % 100) > 9 ? (this.getYear() % 100).toString() : '0' + (this.getYear() % 100));
    str = str.replace(/MM/, (parseInt(this.getMonth() + 1) > 9 ? parseInt(this.getMonth() + 1).toString() : ('0' + parseInt(this.getMonth() + 1))));
    str = str.replace(/M/g, this.getMonth());
    str = str.replace(/w|W/g, Week[this.getDay()]);
    str = str.replace(/dd|DD/, this.getDate() > 9 ? this.getDate().toString() : '0' + this.getDate());
    str = str.replace(/d|D/g, this.getDate());

    str = str.replace(/hh|HH/, this.getHours() > 9 ? this.getHours().toString() : '0' + this.getHours());
    str = str.replace(/h|H/g, this.getHours());
    str = str.replace(/mm/, this.getMinutes() > 9 ? this.getMinutes().toString() : '0' + this.getMinutes());
    str = str.replace(/m/g, this.getMinutes());

    str = str.replace(/ss|SS/, this.getSeconds() > 9 ? this.getSeconds().toString() : '0' + this.getSeconds());
    str = str.replace(/s|S/g, this.getSeconds());
    return str;
}